﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AvansRS.Domain.DataInterface;
using AvansRS.Domain;
using NHibernate;
using NHibernate.Criterion;
using StructureMap;

namespace AvansRS.Data
{
	public class GroupRepository : BaseRepository<Group>, IGroupRepository
	{
		public override void Add(Group domainObject)
		{
// 			BaseRepository<Entity> repEntity = new BaseRepository<Entity>();
// 			repEntity.Add(domainObject.Entity);

			base.Add(domainObject);
		}

		public Group GetByName(string name)
		{
			using(ISession session = SessionProvider.GetSession())
			{
				Group group = session.CreateCriteria(typeof(Group))
					 .Add(Expression.Eq("Name", name))
					.UniqueResult<Group>();
				return group;
			}
		}

		public void DeleteMember(int groupID, int personID)
		{
			using(ISession session = SessionProvider.GetSession())
			{
				Person person = session.CreateCriteria(typeof(Group))
					.Add(Expression.Eq("ID", groupID))
					.CreateCriteria("Members")
					.Add(Expression.Eq("ID", personID))
					.UniqueResult<Person>();
					

			}
		}
	}
}
